<template>
	<view class="homeLayout pageBg">
		<CustomNavBar title="推荐"></CustomNavBar>
		<!-- 轮播图 -->
		<view class="banner">
			<swiper indicator-dots='true' indicator-color=rgba(255,255,255,0.5) indicator-active-color="#fff" autoplay
				circular>
				<swiper-item v-for="(item,index) of bannerList" :key="item._id">
					<image :src="item.picurl" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>

		<!-- 上下滚动栏 -->
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="20"></uni-icons>
				<text>公告</text>
			</view>
			<view class="middle">
				<swiper vertical autoplay interval="2500" duration="300" circular>
					<swiper-item v-for="(item,index) in 4" :key="index">this is a test</swiper-item>
				</swiper>
			</view>
			<view class="right">
				<uni-icons type="right" size="16" color="#333"></uni-icons>
			</view>
		</view>

		<!-- 每日推荐区域 -->
		<view class="select">
			<CommonTitle>
				<template #left>
					每日推荐
				</template>
				<template #right>
					<view class="data">
						<uni-icons type="calendar-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">
							<uni-dateformat :date="Date.now()" format="dd日"></uni-dateformat>
						</view>
					</view>
				</template>
			</CommonTitle>
			<view class="content">
				<scroll-view scroll-x>
					<view class="box" v-for="(item,index) of selectList" :key="item._id">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>

		<!-- 主题区域 -->
		<view class="theme">
			<CommonTitle>
				<template #left>
					专题精选
				</template>
				<template #right>
					<navigator url="" class="more">More+</navigator>
				</template>
			</CommonTitle>

			<view class="content">
				<ThemeItem v-for="(item,index) of themeList" :item="item" :key=" item._id"></ThemeItem>
				<ThemeItem :flag='true'></ThemeItem>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';

	import {
		apiGetHomeBanner,
		apiGetSelectList,
		apiGetThemeList
	} from '@/api/api.js'


	let bannerList = ref([])
	let selectList = ref([])
	let themeList = ref([])


	/**
	 * 获取轮播图图片
	 */
	async function getBannerPhoto() {
		let ret = await apiGetHomeBanner();
		bannerList.value = ret.data
	}
	getBannerPhoto()


	/**
	 * 获取每日推荐图片
	 */
	async function getSelectPhoto() {
		let ret = await apiGetSelectList();
		selectList.value = ret.data
	}
	getSelectPhoto()


	/**
	 * 获取主题区域图片
	 */
	async function getThemePhoto() {
		let ret = await apiGetThemeList({
			select: true
		});
		themeList.value = ret.data;
		console.log(themeList.value);
	}
	getThemePhoto()
</script>

<style lang="scss" scoped>
	.banner {
		width: 750rpx;
		padding: 30rpx 0;

		swiper {
			width: 750rpx;
			height: 340rpx;

			swiper-item {
				width: 100%;
				height: 100%;
				padding: 0 30rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.notice {
		width: 690rpx;
		height: 80rpx;
		background-color: #f9f9f9;
		border-radius: 80rpx;
		display: flex;
		margin: 0 auto;

		.left {
			width: 140rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			:deep(.uni-icons) {
				color: $brand-theme-color !important;
			}

			text {
				font-weight: 600;
				font-size: 28rpx;
				color: #28b389;
			}
		}

		.middle {
			flex: 1;

			swiper {
				height: 100%;

				swiper-item {
					height: 100%;
					line-height: 80rpx;
					font-size: 30rpx;
					color: #666;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
			}
		}

		.right {
			width: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.select {
		.data {
			color: "#28b389";
			display: flex;
			align-items: center;

			.text {
				margin-left: 5rpx;
			}
		}

		padding-top:50rpx;

		.content {
			width: 720rpx;
			margin-left: 30rpx;
			margin-top: 30rpx;

			scroll-view {
				white-space: nowrap;

				.box {
					width: 200rpx;
					height: 430rpx;
					display: inline-block;
					margin-right: 15rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}

				.box:last-child {
					margin-right: 30rpx;
				}
			}

		}
	}

	.theme {
		.more {
			font-size: 32rpx;
			color: #888;
		}

		padding:50rpx 0;

		.content {
			margin-top: 30rpx;
			padding: 0 30rpx;
			display: grid;
			gap: 15rpx;
			grid-template-columns: repeat(3, 1fr);
		}
	}
</style>